package com.qf.ayc.shopcart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.ayc.orders.entity.Orders;
import com.qf.ayc.shopcart.entity.Shopcart;
import com.qf.ayc.shopcart.mapper.ShopcartMapper;
import com.qf.ayc.shopcart.service.IShopcartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author BeautyFairy
 * @since 2024-02-21
 */
@Service
@Slf4j
public class ShopcartServiceImpl extends ServiceImpl<ShopcartMapper, Shopcart> implements IShopcartService {
    @Autowired
    private ShopcartMapper shopcartMapper;

    @Override
    public List<Shopcart> getshoplist(Integer pageNum, Integer limit) {
        QueryWrapper<Shopcart> shopcartWrapper = new QueryWrapper<>();
        Page<Shopcart> shopcartPage = new Page<>(pageNum,limit);

        shopcartMapper.selectPage(shopcartPage,shopcartWrapper);
        int total =(int) shopcartPage.getTotal();
        log.info("tatal总数据条数:{}",total);
        if(total-pageNum*limit>0||total-pageNum*limit==0||(pageNum*limit-total<limit)){
            shopcartMapper.selectPage(shopcartPage,shopcartWrapper);
            List<Shopcart> records = shopcartPage.getRecords();
            return records;
        }else{
            return null;
        }


    }

    @Override
    public List<Shopcart> List() {
        QueryWrapper<Shopcart> queryWrapper = new QueryWrapper<>();
        List<Shopcart> carts = shopcartMapper.selectList(queryWrapper);
        log.info("订单信息=", carts);
        return carts;
    }
}
